import { Inject, Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository, In } from 'typeorm';
import { PackageInfoEntity } from '../entity/info';

/**
 * 套餐信息
 */
@Provide()
export class PackageInfoService extends BaseService {
  @InjectEntityModel(PackageInfoEntity)
  packageInfoEntity: Repository<PackageInfoEntity>;

  async getPackageTotalMoney(ids: number[]) {
    const packages = await this.packageInfoEntity.find({
      where: {id: In(ids)}
    })
    return packages.reduce((total, packageVal) => Number(total) + Number(packageVal.price), 0);
  }
}
